//
//  LPKDetailsController.m
//  Demo-01
//
//  Created by 李平宽 on 2017/1/21.
//  Copyright © 2017年 com.lpk. All rights reserved.
//

#import "LPKDetailsController.h"
#import "UILabel+Addition.h"
#import "UIColor+Addition.h"
#import "Masonry.h"
#import "LPKNetWorkTools.h"
#import "LPKHomeDetailCell.h"
#import "YYModel.h"

static NSString *DetailID = @"cell";
@interface LPKDetailsController ()<UITableViewDataSource,UITabBarDelegate>



@end

@implementation LPKDetailsController
{
    NSArray *_dataList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self loadDataDetailId:self.Id];
    [self setupUI];
   
}
- (void)setupUI
{
    [self.tableView registerClass:[LPKHomeDetailCell class] forCellReuseIdentifier:DetailID];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.estimatedRowHeight = 600;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.allowsSelection = NO;
    
}

#pragma mark - UITableViewDataSource,UITabBarDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataList.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    LPKHomeDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:DetailID forIndexPath:indexPath];
    LPKHomeDetailModel *model = _dataList[0];
    cell.model = model;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark - 加载数据
- (void)loadDataDetailId:(NSString *)Id
{
    [[LPKNetWorkTools sharedNetWorkTools] homeViewDetailDataId:Id success:^(id responseObject) {
        NSLog(@"%@",responseObject);
        
        NSString *key = @"result";
        NSArray *dictArr = responseObject[key];
        
        _dataList = [NSArray yy_modelArrayWithClass:[LPKHomeDetailModel class] json:dictArr];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

@end
